package visual;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

import logic.Player;
import main.GameDef;

public class Board extends JPanel implements MouseListener, GameDef{
	public final static int WIDTH = 26;
	public final static int HEIGHT = 26;
	public Player player;
	
	public Board(){
		addMouseListener(this);
	}
	
	public void paint(Graphics g){
		g.setColor(new Color(0x000000));
		g.fillRect(0, 0, getWidth(), getHeight());
		if(player != null){
			for(int i = 0; i < player.castle.size(); i++){
				g.setColor(getPieceColor(player.castle.get(i).type));
				for(int j = 0; j < player.castle.get(i).blocks.size(); j++){
					Rectangle rect = player.castle.get(i).blocks.get(j).position;
					g.fillRect(rect.x, rect.y, rect.width, rect.height);
				}
			}
		}
		g.setColor(new Color(0xFFFFFF));
		for(int i = 0; i < HEIGHT; i++){
			g.drawLine(0, i * getHeight() / HEIGHT, getWidth(), i * getHeight() / HEIGHT);
		}
		for(int i = 0; i < WIDTH; i++){
			g.drawLine(i * getWidth() / WIDTH, 0, i * getWidth() / WIDTH, getHeight());
		}
	}
	
	public void setPlayer(Player _player){
		player = _player;
	}

	public Color getPieceColor(int pieceType){
		switch(pieceType){
			case ID_INTERIOR:
				return new Color(COLOR_INTERIOR);
			case ID_HOUSE:
				return new Color(COLOR_HOUSE);
			case ID_CATAPULT:
				return new Color(COLOR_CATAPULT);
			case ID_CANNON:
				return new Color(COLOR_CANNON);
			case ID_ARMORY:
				return new Color(COLOR_ARMORY);
		}
		return new Color(COLOR_DEFAULT);
	}
	
	
	public void mouseClicked(MouseEvent e) {
		System.out.println("arg0: " + e);
	}

	public void mouseEntered(MouseEvent e) {
	}

	public void mouseExited(MouseEvent e) {
	}

	public void mousePressed(MouseEvent e) {
	}

	public void mouseReleased(MouseEvent e) {
	}
}
